package com.archermind.boc.dal.business.service;

import java.util.List;

import org.hibernate.HibernateException;

import org.hibernate.Session;

import com.archermind.boc.Logger;

import com.archermind.boc.dal.mode.HibernateSessionFactory;
import com.archermind.boc.domain.BizTimeout;

public class BizTimeoutService {
	private Logger log = Logger.getLogger(BizTimeoutService.class.getName());

	public BizTimeout findtype(int id) {
		Session session = null;
		BizTimeout bizTime = null;
		try {
			session = HibernateSessionFactory.getSession();
			bizTime = (BizTimeout) session.get(BizTimeout.class, id);
		} catch (HibernateException e) {
			log.error("err : Query is fail!", e);
		} finally {
			HibernateSessionFactory.closeSession(session);
		}
		return bizTime;
	}

	@SuppressWarnings("unchecked")
	public BizTimeout findByTypeId(String typeId) {
		Session session = null;
		BizTimeout bizTime = null;
		try {
			session = HibernateSessionFactory.getSession();
			List<BizTimeout> ls = session.createQuery(
					"from BizTimeout b where b.typeID=?").setParameter(0,
					typeId).list();
			if (ls != null && ls.size() > 0) {
				bizTime = (BizTimeout) ls.get(0);
			} else {
				return null;
			}
		} catch (HibernateException e) {
			log.error("err : Query is fail!", e);
		} finally {
			session.close();
		}
		return bizTime;
	}

}
